package org.yzh.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.yzh.web.endpoint.WaterMeterEndpoint;
import org.yzh.web.waterMeter.common.WaterMeterMessageId;
import org.yzh.web.waterMeter.dto.WaterMeterReadingReq;
import org.yzh.web.waterMeter.dto.basics.WaterMeterMessage;


import java.util.Date;


@Api(description = "water meter api")
@Controller
@RequestMapping("water")
public class WaterMeterController {

    @Autowired
    private WaterMeterEndpoint endpoint;

    @ApiOperation(value = "获取水表信息")
    @RequestMapping(value = "{hubId}/reading", method = RequestMethod.POST)
    @ResponseBody
    public WaterMeterMessage updateParameters(@PathVariable("hubId") String hubId) {
        WaterMeterMessage message = new WaterMeterMessage(0x0D, 0x4B,  WaterMeterMessageId.WaterMeterReading,
                hubId);
        WaterMeterReadingReq body = new WaterMeterReadingReq();
        body.setDateTime(new Date());
        message.setBody(body);
        WaterMeterMessage response = (WaterMeterMessage) endpoint.ayncSend(message);
        return response;
    }

}